home *** CD-ROM | disk | FTP | other *** search
- #include "stdafx.h"
-
- cCatapult::cCatapult(int _x, int _y, cProperties *_orig)
- : cStructure(_x, _y, _orig)
- {
- angle = orig->params->get_fix("*ANGLE", 64);
- range = orig->params->get_int("*RANGE", 150);
- max_speed = orig->params->get_int("*MAX_SPEED", 0);
- max_acceleration = orig->params->get_int("*MAX_ACCELERATION", 250);
- height_to_activate = orig->params->get_int("*HEIGHT_TO_ACTIVATE", GAME_DY);
- push_granularity = orig->params->get_fix("*PUSH_GRANULARITY", 0.2);
- limit_speed = orig->params->get_bool("*LIMIT_SPEED", FALSE);
-
- orig->get_sequence("INACTIVE", inactive_seq);
- orig->get_sequence("ACTIVE", active_seq);
-
- // Check if there's an inactive sequence
-
- if (inactive_seq.start_frame == 0)
- {
- active = TRUE;
- set_sequence(active_seq, TRUE);
- }
- else
- {
- active = FALSE;
- set_sequence(inactive_seq);
- }
- }
-
- int cCatapult::do_catapult(cMovable *_c, cDisplayable *_g, cCircle *, cCircle *)
- {
- cCatapult *c = (cCatapult *)_c;
- cGameObject *g = (cGameObject *)_g;
-
- // Check if this object is influenced by catapults
-
- if (!g->influenced_by_catapult)
- return FALSE;
-
- // Compute acceleration
-
- int d = (int)sqrt(d_square(g->x - c->x, g->y - c->y)),
- a = c->max_acceleration * (c->range - d) / c->range,
- v = c->max_speed * (c->range - d) / c->range;
-
- // Push object
-
- if (a > 0)
- g->new_angular_push(c->push_granularity, 0, a, c->angle);
-
- if (v > 0)
- {
- if (c->limit_speed)
- {
- if ((fix)v > g->get_speed(c->angle))
- g->add_angular_speed((fix)v - g->get_speed(c->angle), c->angle);
- }
- else
- {
- g->add_angular_speed(v, c->angle);
- }
- }
-
- return TRUE;
- }
-
- int cCatapult::control()
- {
- cGameObject::control();
-
- // Activate catapult
-
- if (!active && animation_done())
- {
- active = y2 - surface->start < height_to_activate;
- set_sequence(active? active_seq : inactive_seq);
- }
-
- // Do active thing
-
- if (active)
- {
- if (animation_done())
- {
- active = FALSE;
- set_sequence(inactive_seq);
- }
- else if (!push_wait)
- {
- check_radial_boundaries(circle_bounds, players, do_catapult);
- check_radial_boundaries(circle_bounds, weapons, do_catapult);
- check_radial_boundaries(circle_bounds, bonus, do_catapult);
-
- push_wait = push_granularity * sec;
- }
- }
-
- return !below_screen();
- }
-